#ifndef TCP_ACCEPTER_H
#define TCP_ACCEPTER_H

#include <functional>
#include <utility>
#include <netinet/in.h>

#include "Socket.h"
#include "InetAddress.h"

class Acceptor{
public:
    typedef std::function<void (int sockfd, const InetAddress &)> NewConnectionCallback;

    Acceptor(int port);

    void listen();

    void setNewConnectionCallback(NewConnectionCallback newConnectionCallback){
        newConnectionCallback_ = std::move(newConnectionCallback);
    }

private:
    void handleRead();

    InetAddress addr_;
    // 保存对应的socket
    Socket socket_;
    // 保存文件描述符
    NewConnectionCallback newConnectionCallback_;
    // 有新连接之后调用的回调函数
    bool listenning_;
    // 是否在监听中
};

#endif //TCP_ACCEPTER_H
